package com.transfer.Scheduler;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;

import com.transfer.conf.FileTransferConfiguration;
import com.transfer.conf.FileTransferProperties;

public class TransferScheduler {
    private static int fixedParallelism=FileTransferConfiguration.fixedParallelism;
    private static ThreadPoolExecutor fixedExecutor;
    static{
      fixedExecutor=(ThreadPoolExecutor)Executors.newFixedThreadPool(fixedParallelism);
    }
    
    public static void clear(){
      fixedExecutor.shutdown();
    }
    
    public static ThreadPoolExecutor getFixedExecutor() {
        return fixedExecutor;
    }
   /* public static void main(String[] args) {
        long startTime=System.currentTimeMillis();   //获取开始时间
        TransferScheduler multiClient = new TransferScheduler(80);
        multiClient.init();
        ThreadPoolExecutor executor = (ThreadPoolExecutor) multiClient
                .getFixedExecutor();
        System.out.printf("Main: begin\n");
        
        FileTransferTask task=new FileTransferTask("127.0.1.1",10012,"C://mywork/test.txt",1);
        List<FileSliceTransferTask> runnableTaskList=task.getRunnableTaskList();
        System.out.printf("Main: begin\n"+runnableTaskList.size());
        for(FileSliceTransferTask sliceTask:runnableTaskList){
            executor.submit(sliceTask);
        }
        FileTransferTask task1 = new FileTransferTask("C://mywork/要求.txt");
        FileTransferTask task2 = new FileTransferTask("C://mywork/信息.txt");
        executor.submit(task1);
        executor.submit(task2);
        // Wait for the finalization of the two tasks
        do {
            try {
                Thread.sleep(5000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        } while (executor.getCompletedTaskCount() < runnableTaskList.size());
        long endTime=System.currentTimeMillis(); //获取结束时间
        System.out.println("程序运行时间： "+(endTime-startTime)+"ms");
        System.out.printf("Main: end\n");
        // Shutdown the executor
        executor.shutdown();
    }*/

}
